package com.zhouyibike.uu.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhouyibike.uu.R;
import com.zhouyibike.uu.entity.MyBikeResult;

import java.util.HashMap;

/**
 * Created by cc on 2017/5/22.
 */

public class MyBikeAdapter extends BaseAdapter {
    private Context  context;
    private MyBikeResult.DataBean list;
    private HashMap<String,Boolean> presstag=new HashMap<>();
    private int page,totalpages;
    public MyBikeAdapter(Context context, MyBikeResult.DataBean list,int page,int totalpages) {
        this.context = context;
        this.list = list;
        this.page=page;
        this.totalpages=totalpages;
    }
    public void setpreid(String pressid){
        if(presstag.containsKey(pressid)){
            presstag.remove(pressid);
        }else {
            presstag.put(pressid, true);
        }
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        if(page==-1) {
            return list.getBicycles().size();
        }else{
           if(page+1==totalpages){
               return list.getBicycles().size()-page*9;
           }else{
               return 9;
           }
        }
    }

    @Override
    public Object getItem(int position) {
        return list.getBicycles().get(position+9*page);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        convertView= LayoutInflater.from(context).inflate(R.layout.item_chongzhilist,null);
        TextView textView= (TextView) convertView.findViewById(R.id.tv_itemchongzhi_p);
        if(presstag.containsKey(list.getBicycles().get(position))){
            textView.setBackgroundResource(R.drawable.miaobian_bg_pressed);
            textView.setTextColor(context.getResources().getColor(R.color.color_dark));
        }else{
            textView.setBackgroundResource(R.drawable.miaobian_bg_notpressed);
            textView.setTextColor(context.getResources().getColor(R.color.text_main_3));
        }
        textView.setText(list.getBicycles().get(position+page*9));
        convertView.setTag(list.getBicycles().get(position+page*9));
        return convertView;
    }
}
